package com.example.result

object Algorithm {
    //    @JvmStatic
    var id: Int = 0

    init {
        System.loadLibrary("algorithms_fourth_jni")
        setPanic()
    }

    external fun markdownToHtml(data: String): String
    external fun huffmanEncode(data: String): ByteArray
    external fun huffmanDecode(encoderResult: ByteArray): String
    external fun hello(input: String): String
    var redBlackST: Long? = null
    external fun createRedBlackST(): Long
    external fun setPanic()
    external fun closeRedBlackST(redBlackST: Long)
    external fun inertOrUpdateNodeToRedBlackST(redBlackST: Long, k: String, v: Int)
    external fun deleteNodeToRedBlackST(redBlackST: Long, k: String): Int
    external fun minNodeToRedBlackST(redBlackST: Long): String?
    external fun printRedBlackST(redBlackST: Long): String
    external fun maxNodeToRedBlackST(redBlackST: Long): String?
    external fun getValueToRedBlackST(redBlackST: Long, k: String): Int
    external fun hasNodeToRedBlackST(redBlackST: Long, k: String): Boolean

}

fun ByteArray.format(): String {
    return this.let {
        val content = it.fold("") { a, b -> "$a,$b" }
        "len:${it.size}\ncontent:[$content]"
    }
}
